package cn.tedu.smartsite.user.controller;

import cn.tedu.smartsite.base.response.JsonResult;
import cn.tedu.smartsite.user.pojo.dto.UserLoginParam;
import cn.tedu.smartsite.user.pojo.dto.UserQuery;
import cn.tedu.smartsite.user.pojo.vo.UserVO;
import cn.tedu.smartsite.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("login")
    public JsonResult login(UserLoginParam userLoginParam) {
        log.debug("用户登录: {}",userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }

    @GetMapping("select")
    public JsonResult select(UserQuery userQuery) {
        log.debug("查询用户: {}",userQuery);
        List<UserVO> list = userService.select(userQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Long id) {
        log.debug("删除用户: {}",id);
        userService.delete(id);
        return JsonResult.ok();
    }
}
